from typing import List

from sqlalchemy.ext.asyncio import AsyncSession
from src.modules.ai_models.model_loaders.model_loader import get_text_embedding_model
from src.modules.knowbase.repository.dao.imagevector_dao import ImageVectorDao


class ImageVectorService:
    @staticmethod
    async def get_imagevector_list(user_id:str = None,
                                   file_id:str = None,
                                   kb_id: str = None,
                                   page: int =1 ,page_size:int = 10):

        return await ImageVectorDao.get_imagevector_list(user_id, file_id,
                                                         kb_id,page, page_size)

    @staticmethod
    async def get_image_vector_list_for_rag(question_vector: List[float],
                                            session: AsyncSession,
                                            knowbase_ids: List[str],
                                            top_k: int):
        return await ImageVectorDao.get_imagevector_list_for_rag(question_vector=question_vector,
                                                                 session=session,
                                                                 knowbase_ids=knowbase_ids,
                                                                 top_k=top_k)

    @staticmethod
    async def delete_vector(vector_id:str):
        return await ImageVectorDao.delete_vector(vector_id)


    @staticmethod
    async def update_image_vector_by_id(vector_id:str, image_desc:str):
        text_embedding_model = get_text_embedding_model()
        desc_vector = text_embedding_model.get_text_embedding(image_desc)
        return await ImageVectorDao.update_image_vector_by_id(vector_id,image_desc,desc_vector)
